using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PractBTS.ErrorsCollection.Logic;

namespace PractBTS.ErrorsCollection.EnableRoutingFailure
{
    public partial class MainWindow : Form
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void MainWindow_Load(object sender, EventArgs e)
        {
            List<PB_BTSGroup> list = PB_BTSGroup.GetGroups();
            foreach (PB_BTSGroup grp in list)
            {
                this.cbBizTalkGroup.Items.Add(grp.Name);
            }
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            List<PB_BTSGroup> groups = PB_BTSGroup.GetGroups();
            PB_BTSGroup group = null;
            string selectedgroup =  this.cbBizTalkGroup.SelectedItem as string;

            if((selectedgroup != null)&& (selectedgroup!= string.Empty))
            {
                foreach (PB_BTSGroup grp in groups)
                {
                    if (grp.Name == selectedgroup)
                    {
                        group = grp;
                        break;
                    }
                }
            }
            else
            {
                group = groups[0];
               
            }
         List<PB_BTSSendPort> sendPorts = group.GetSendPorts();
         List<PB_BTSReceivePort> receivePorts = group.GetReceivePorts();
            string str1 = string.Empty;
            if(this.cbReceivePorts.Checked)
            {
            foreach (PB_BTSReceivePort sp in receivePorts)
                {
                    sp.EnableRouting();
                }
                str1 += "(Receive Ports)";
            }
            if(this.cbSendPorts.Checked)
            {
                foreach (PB_BTSSendPort sp in sendPorts)
                {
                    sp.DisableRouting();
                }
                str1 += "(Send Ports)";

            }
            MessageBox.Show(string.Format("Enabled all {0} on {1}",str1,group.Name));
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}